package com.source.lightfowl.basedata.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;
import org.springframework.format.annotation.DateTimeFormat;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;

/**
 * @Author: Faink
 * @CreateTime: 2020/8/4 20:20
 */
@Data
@Entity
@Table(name="barcode_machine_alert")
@JsonIgnoreProperties(value={"hibernateLazyInitializer"})
public class MachineAlert implements Serializable {

    @Id
    private String id;//

    private String barcodeMachineId;//脚标机编号
    private String faultInfo;//故障信息
    private String state;//故障状态（0：未处理、1：已处理）
    private String remarks;//备注
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(shape = JsonFormat.Shape.STRING,pattern = "yyyy-MM-dd",timezone = "GMT-8")
    private java.util.Date faultTime;//故障时间
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(shape = JsonFormat.Shape.STRING,pattern = "yyyy-MM-dd",timezone = "GMT-8")
    private java.util.Date createDate;//创建时间
    private int isRead;

    @OneToOne(targetEntity = BarcodeMachine.class,fetch = FetchType.LAZY)
    @JoinColumn(name = "barcodeMachineId",referencedColumnName = "id",insertable = false,updatable = false)
    @NotFound(action = NotFoundAction.IGNORE)
    private BarcodeMachine machine;


    //10_4 xcy添加 冗余字段
    @Transient //不会映射到数据库
    private String stallsName; //档口名
    @Transient
    private String linkName; //联系人


    public MachineAlert() {
    }

    public MachineAlert(String id, String barcodeMachineId, String faultInfo, String state, String remarks, Date faultTime, Date createDate, int isRead) {
        this.id = id;
        this.barcodeMachineId = barcodeMachineId;
        this.faultInfo = faultInfo;
        this.state = state;
        this.remarks = remarks;
        this.faultTime = faultTime;
        this.createDate = createDate;
        this.isRead = isRead;
    }
}
